package com.iamteer.contact.util;

import java.io.File;
import java.io.FileOutputStream;

import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;

public class XMLUtil {
	
	public static Document getDocument(File file) {
		try {
			Document doc = new SAXReader().read(file);
			return doc;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
	public static void write2xml(Document doc, File file) {
		try {
			FileOutputStream out = new FileOutputStream(file);
			OutputFormat format = OutputFormat.createPrettyPrint();
			XMLWriter writer = new XMLWriter(out, format);
			writer.write(doc);
			writer.close();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
